package com.glsc.ngateway.oaflow.controller;

import com.alibaba.fastjson.JSON;
import com.glsc.ngateway.common.api.oaflow.dto.SyncPlatformFlowCommonDto;
import com.glsc.ngateway.common.api.oaflow.resp.OaflowResponse;
import com.glsc.ngateway.oaflow.service.AddFlowService;
import com.glsc.ngateway.oaflow.service.OaSyncService;
import com.glsc.ngateway.common.api.oaflow.resp.InterfaceResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 同步oa和网关流程
 *
 * @author xuchang
 */
@RestController
@RequestMapping("/syncflow")
@Slf4j
public class OaSyncController {

    @Autowired
    private OaSyncService oaSyncService;

    @Autowired
    AddFlowService addFlowService;

    @PostMapping("/syncFlow2Oa")
    public OaflowResponse<Void> syncFlow2Oa(@RequestBody SyncPlatformFlowCommonDto<?> param) {
        try {
            oaSyncService.syncFlow2Oa(param);
            return OaflowResponse.success();
        } catch (Exception e) {
            log.error("异常", e);
            return OaflowResponse.failMsg(e.getMessage());
        }
    }

    @PostMapping(value = "/endOaFlow")
    public OaflowResponse<String> endOaFlow(@RequestParam("workflowId") String workflowId, @RequestParam("taskId") String taskId) {
        Map<String, String> map = addFlowService.endOaFlow(workflowId, taskId);
        return OaflowResponse.successData(JSON.toJSONString(InterfaceResponse.returnSuccss(map)));
    }

}
